from pydantic import BaseModel, Field
from datetime import datetime
from typing import Optional

class UserBase(BaseModel):
    # 必填字段
    username: str = Field(..., description="用户名", min_length=3, max_length=50)
    real_name: str = Field(..., description="真实姓名", min_length=1, max_length=50)
    password: str = Field(..., description="密码（加密存储）", min_length=6, max_length=100)
    
    # 可选字段
    phone: Optional[str] = Field(None, description="手机号", max_length=20)
    email: Optional[str] = Field(None, description="邮箱", max_length=100)
    status: int = Field(1, description="状态：0-禁用 1-启用")

class UserCreate(UserBase):
    """创建用户时使用的模型"""
    
    class Config:
        from_attributes = True

class UserUpdate(BaseModel):
    """更新用户时使用的模型"""
    real_name: Optional[str] = None
    password: Optional[str] = None
    phone: Optional[str] = None
    email: Optional[str] = None
    status: Optional[int] = None
    
    class Config:
        from_attributes = True

class User(UserBase):
    id: int
    create_time: Optional[datetime] = Field(None, description="创建时间")
    update_time: Optional[datetime] = Field(None, description="更新时间")
    
    class Config:
        from_attributes = True

class LoginResponse(BaseModel):
    """登录响应模型"""
    access_token: str
    token_type: str
    user: User

class UserInfoResponse(BaseModel):
    """用户信息响应模型"""
    user: User
